﻿using DingTalk.Common;
using DingTalk.Common.SqlHelper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace DingTalk.Service
{
    public class DingService
    {
        public DingService()
        {

        }

        /// <summary>
        /// 执行语句
        /// </summary>
        /// <param name="act"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static ActResult NonQuery(ActResult act, string sql)
        {
            if (string.IsNullOrWhiteSpace(AppConfigurtaionHelper.Configuration["AppSetting:ConnectSys"]))
            {
                act.msg = "数据库链接错误！AppSetting:ConnectSys";
                return act;
            }
            int t = SqlHelper.ExecuteNonQuery(AppConfigurtaionHelper.Configuration["AppSetting:ConnectSys"], CommandType.Text, sql);
            if (t > 0)
            {
                act.code = 0;
                act.msg = "操作成功！";
            }
            return act;
        }

        public static ActResult NonQuery(ActResult act, string sql, string appset)
        {
            if (string.IsNullOrWhiteSpace(AppConfigurtaionHelper.Configuration["AppSetting:" + appset]))
            {
                act.msg = "数据库链接错误！AppSetting:ConnectSys";
                return act;
            }
            int t = SqlHelper.ExecuteNonQuery(AppConfigurtaionHelper.Configuration["AppSetting:" + appset], CommandType.Text, sql);
            if (t > 0)
            {
                act.code = 0;
                act.msg = "操作成功！";
            }
            return act;
        }
        /// <summary>
        /// DataTable
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static DataTable GetTable(string str)
        {
            if (string.IsNullOrWhiteSpace(AppConfigurtaionHelper.Configuration["AppSetting:ConnectSys"]))
            {
                return new DataTable();
            }
            DataSet ds = SqlHelper.ExecuteDataset(AppConfigurtaionHelper.Configuration["AppSetting:ConnectSys"], CommandType.Text, str);
            return ds.Tables[0];
        }

        public static DataTable GetTable(string str, string appset)
        {
            if (string.IsNullOrWhiteSpace(AppConfigurtaionHelper.Configuration["AppSetting:" + appset]))
            {
                return new DataTable();
            }
            DataSet ds = SqlHelper.ExecuteDataset(AppConfigurtaionHelper.Configuration["AppSetting:" + appset], CommandType.Text, str);
            return ds.Tables[0];
        }
    }
}
